<template>
  <div :class="appClass">
    <div class="container">
      <h1>Emotion CSS-in-JS with Vue 3</h1>

      <div class="controls">
        <label>
          <input type="checkbox" v-model="isDarkTheme"> Dark Mode
        </label>
        <label>
          <input type="range" min="0" max="5" v-model="elevation"> Elevation: {{ elevation }}
        </label>
      </div>

      <div class="components-grid">
        <div class="section">
          <h2>Dynamic Buttons</h2>
          <div class="button-group">
            <DynamicButton variant="primary">Primary</DynamicButton>
            <DynamicButton variant="secondary">Secondary</DynamicButton>
            <DynamicButton variant="danger" size="small">Small Danger</DynamicButton>
            <DynamicButton variant="warning" size="large">Large Warning</DynamicButton>
            <DynamicButton variant="success" rounded>Rounded Success</DynamicButton>
          </div>
        </div>

        <div class="section">
          <h2>Theme Cards</h2>
          <div class="cards">
            <ThemeCard :elevation="elevation" accent-color="var(--primary)">
              <template #header>Primary Card</template>
              <p>This is a card with primary accent color and elevation level {{ elevation }}.</p>
            </ThemeCard>

            <ThemeCard :elevation="elevation" accent-color="var(--danger)">
              <template #header>Danger Card</template>
              <p>This card uses the danger color as its accent.</p>
            </ThemeCard>
          </div>
        </div>

        <div class="section">
          <h2>Animated Box</h2>
          <AnimatedBox />
          <p>Click the box to toggle bounce animation</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';
import { css } from '@emotion/css';
import { theme, darkTheme } from './styles/theme';
import DynamicButton from './components/DynamicButton.vue';
import ThemeCard from './components/ThemeCard.vue';
import AnimatedBox from './components/AnimatedBox.vue';

const isDarkTheme = ref(false);
const elevation = ref(2);

// 应用CSS变量
const appClass = computed(() => {
  const currentTheme = isDarkTheme.value ? darkTheme : theme;

  return css`
    min-height: 100vh;
    padding: 40px 20px;
    background: ${isDarkTheme.value ? '#1a1a2e' : '#f5f7fa'};
    color: ${isDarkTheme.value ? '#e0e0e0' : '#333'};
    transition: background 0.3s ease, color 0.3s ease;

    // 设置CSS变量
    --primary: ${currentTheme.primary};
    --secondary: ${currentTheme.secondary};
    --danger: ${currentTheme.danger};
    --warning: ${currentTheme.warning};
    --success: ${currentTheme.success};
    --border-radius: ${currentTheme.borderRadius};
    --transition: ${currentTheme.transition};
    --box-shadow: ${currentTheme.boxShadow};
  `;
});
</script>

<style>
/* 全局样式 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  text-align: center;
  margin-bottom: 40px;
  color: var(--primary);
}

.controls {
  background: rgba(0, 0, 0, 0.05);
  padding: 20px;
  border-radius: var(--border-radius);
  margin-bottom: 30px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.components-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 30px;
}

.section {
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: var(--border-radius);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
</style>
